package com.kakavr.shop.service;

import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.apache.commons.lang3.math.NumberUtils;
import org.joda.time.DateTime;
import org.springframework.stereotype.Service;

import com.github.pagehelper.PageHelper;
import com.kakavr.base.service.BaseService;
import com.kakavr.page.Pagination;
import com.kakavr.page.constant.PaginationConstant;
import com.kakavr.shop.dao.IRegionAdminDao;

@Service
public class RegionAdminService extends BaseService implements
		IRegionAdminService {
	@Resource
	private IRegionAdminDao regionAdminDao;

	@Override
	public void addRegion(Map<String, Object> map) {
		map.put("createtime", DateTime.now().toDate());
		regionAdminDao.addRegion(map);
	}

	@Override
	public void updateRegion(Map<String, Object> map) {
		regionAdminDao.updateRegion(map);
	}

	@Override
	public Pagination<Map<String, Object>> selectRegionByPage(
			Map<String, Object> map) {
		PageHelper.startPage(NumberUtils.toInt((String) map
				.get(PaginationConstant.PAGE_NO_NAME)), NumberUtils
				.toInt((String) map.get(PaginationConstant.PAGE_SIZE_NAME)));
		return new Pagination<Map<String, Object>>(
				regionAdminDao.selectRegionByPage(map));
	}

	@Override
	public List<Map<String, Object>> selectRegionList(Map<String, Object> map) {
		return regionAdminDao.selectRegionByPage(map);
	}

}
